# ROOT_HOME = /home/export/base/ycsc_wangjc/zongy/online1/final
ROOT_HOME = /root/final

USE_GPU = -DUSE_GPU
TEST_CNT = 10

CUDAC = nvcc
CUDAOPT = -std=c++17 -O3 -arch=native -Xptxas -O3 --use_fast_math -g $(USE_GPU)
CUDAFLAGS = $(CUDAOPT)
CUDAPATH = $(CUDA_HOME)
LDFLAGS = -lm -lstdc++ -ldl
LDLIBS = $(LDFLAGS) -L$(CUDAPATH)/lib64 -lcudart

JSON_HOME = $(ROOT_HOME)/jsoncpp
JSON_INC  = $(JSON_HOME)/include/json
JSON_LIB  = $(JSON_HOME)/lib

CXX= mpicxx
CFLAGS = -O3 -std=c++17 -fopenmp -g -Wall -DTEST_CNT=$(TEST_CNT) $(USE_GPU)

CL = mpicxx
LFLAGS = -lm -fopenmp -ldl

all: main_f32.exe main_f64.exe check.exe 

cuda_kernel.o: cuda_kernel.cu
	$(CUDAC) -c -I$(CUDA_HOME)/include $(CUDAFLAGS) $< -o $@

my_parcsr.o: my_parcsr.cpp
	$(CXX) -I$(CUDA_HOME)/include $(CFLAGS) -c $^ -o $@

utils.o : utils.cpp
	$(CXX) -I$(CUDA_HOME)/include $(CFLAGS) -c $^ -o $@

coarsen.o: coarsen.cpp
	$(CXX) -I$(CUDA_HOME)/include $(CFLAGS) -c $^ -o $@

AggMG.o: AggMG.cpp
	$(CXX) -I$(CUDA_HOME)/include -I$(JSON_INC) $(CFLAGS) -c $^ -o $@

main_f32.o: main_f32.cpp 
	$(CXX) -I$(CUDA_HOME)/include $(CFLAGS) -c $^ -o $@
main_f64.o: main_f64.cpp 
	$(CXX) -I$(CUDA_HOME)/include $(CFLAGS) -c $^ -o $@

main_f32.exe: main_f32.o my_parcsr.o cuda_kernel.o coarsen.o utils.o AggMG.o
	$(CXX) $^ $(LFLAGS) $(LDLIBS) -L$(JSON_LIB) -ljsoncpp -o $@
main_f64.exe: main_f64.o my_parcsr.o cuda_kernel.o coarsen.o utils.o AggMG.o
	$(CXX) $^ $(LFLAGS) $(LDLIBS) -L$(JSON_LIB) -ljsoncpp -o $@

check.o: check.cpp
	$(CXX) $(CFLAGS) -c $^ -o $@

check.exe: check.o
	$(CXX) $^ $(LFLAGS) -o $@

default: all
.PHONY: all clean

clean:
	rm *.o *.exe

